%处理周期边界条件
function which_cell = find_re_cell(tri, one_b, an_b, index)
%one_b, an_b, 应当是相对应的两个边界
%index 1 up & down, 2 left & right
if(size(one_b,1) ~= size(an_b,1))
    error("维度不匹配，无法对应");
end
n = size(one_b,1);
which_cell = zeros(n,4);
for i = 1 : n
    if index == 1
        sides_node = tri(one_b(i,1)).sides(:,:,one_b(i,2));
        x_min = min([sides_node(1,1),sides_node(2,1)]);
        x_max = max([sides_node(1,1),sides_node(2,1)]);
        for j = 1 : n
            tmp_sides = tri(an_b(j,1)).sides(:,:,an_b(j,2));
            tmp_x_min = min([tmp_sides(1,1),tmp_sides(2,1)]);
            tmp_x_max = max([tmp_sides(1,1),tmp_sides(2,1)]);
            if (x_min == tmp_x_min) && (x_max == tmp_x_max)
                which_cell(i,1:2) = one_b(i,:);
                which_cell(i,3:4) = an_b(j,:);
                break;
            end
        end
    elseif index == 2
        sides_node = tri(one_b(i,1)).sides(:,:,one_b(i,2));
        y_min = min([sides_node(1,2),sides_node(2,2)]);
        y_max = max([sides_node(1,2),sides_node(2,2)]);
        for j = 1 : n
            tmp_sides = tri(an_b(j,1)).sides(:,:,an_b(j,2));
            tmp_y_min = min([tmp_sides(1,2),tmp_sides(2,2)]);
            tmp_y_max = max([tmp_sides(1,2),tmp_sides(2,2)]);
            if (y_min == tmp_y_min) && (y_max == tmp_y_max)
                which_cell(i,1:2) = one_b(i,:);
                which_cell(i,3:4) = an_b(j,:);
                break;
            end
        end
    end
end
end